package com.zyj.myapplication.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.zyj.myapplication.Activity.OrderInfoActivity;
import com.zyj.myapplication.Javabean.UserOrder;
import com.zyj.myapplication.Model.Constant;
import com.zyj.myapplication.R;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by owner on 2017/10/17.
 */

public class FinOrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public FinOrderAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_allorder, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final UserOrder entity = (UserOrder) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.order_id.setText("订单编号：" + entity.getId());
        // Log.v("1231212313", "" + entity.getVstate());
        //viewHolder.order_state.setText("未参加");
        viewHolder.order_state.setText("已完成");
        viewHolder.order_time.setText(entity.getUpdate_time());
        viewHolder.order_allprice.setText("订单总额：" + entity.getPay() + "元");
        if (entity.getName() == null) {
            viewHolder.act_name.setText("此处数据为空");
        } else {
            viewHolder.act_name.setText(entity.getName());
        }
        if (entity.getPrice() == null) {
            viewHolder.act_price.setText("￥300");
        } else {
            viewHolder.act_price.setText("￥" + entity.getPrice());
        }
        if (entity.getThumb() == null) {
            viewHolder.order_pic.setImageResource(R.drawable.tx);
        } else {
            Picasso.with(mContext).load(Constant.PIC_URL + entity.getThumb()).into(viewHolder.order_pic);
        }
       /* viewHolder.act_name.setText(entity.getName());
        viewHolder.act_price.setText("￥" + entity.getPrice());
        String address = "http://172.24.10.175/workout/Uploads/" + entity.getThumb();
        if (!entity.getThumb().equals("")) {
            Picasso.with(mContext).load(address).into(viewHolder.order_pic);
        }*/

        viewHolder.order_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,OrderInfoActivity.class);
                intent.putExtra("order_id",entity.getId());
                intent.putExtra("order_type",entity.getType());
                intent.putExtra("price",entity.getPrice());
                mContext.startActivity(intent);
            }
        });
    }

    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView order_pic;
        TextView order_id, order_state, act_name, act_price, order_time, order_allprice;
        LinearLayout order_info;

        public ViewHolder(View itemView) {
            super(itemView);
            order_pic = (ImageView) itemView.findViewById(R.id.order_pic);
            order_id = (TextView) itemView.findViewById(R.id.order_id);
            order_state = (TextView) itemView.findViewById(R.id.order_state);
            act_name = (TextView) itemView.findViewById(R.id.act_name);
            act_price = (TextView) itemView.findViewById(R.id.act_price);
            order_time = (TextView) itemView.findViewById(R.id.order_time);
            order_allprice = (TextView) itemView.findViewById(R.id.order_allprice);
            order_info = (LinearLayout) itemView.findViewById(R.id.order_info);
        }
    }
}
